package com.yidu.InventoryManagement.mapper;

import com.yidu.CashManagement.entity.FundsAllot;
import com.yidu.InventoryManagement.entity.*;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author 梁俊
 * @date 2022/12/12
 * &@version 1.0
 */
@Mapper
public interface ShouYiZhiFuMapper {
    /**
     * 现金利息收入查询
     * @param map
     * @return
     *
     */
    @Select("SELECT date,c.accountName,c.stockpileType,businessType,money,businessState FROM cashAccrualStock ca INNER JOIN  cash c ON c.cashId=ca.cashId WHERE date LIKE #{date} and date=#{date1} LIMIT #{page},#{limit}")
    public List<XianJinLiXi> selectShouYiZhiFu(Map map);

    /**
     * 取现金应收应付库存数据
     * @return
     */
    @Select("SELECT count(*) FROM cashAccrualStock where date=#{date}")
    public int selectXianJinLiXii(String date);

    /**
     * 删除统计过来现金应收应付重复数据
     * @param businessTime
     * @param businessType
     * @param money
     * @return
     */
    @Delete("delete from cashAccrued where businessTime=#{businessTime} and businessType=#{businessType} and money=#{money}")
    public int deleteCashAccruedd(@Param("businessTime") String businessTime,@Param("businessType") int businessType,@Param("money") int money);


    /**
     * 现金利息收入查询行数
     * @param businessTime
     * @return
     */
    @Select("SELECT COUNT(*) FROM cashAccrualStock ca INNER JOIN  cash c ON c.cashId=ca.cashId WHERE date LIKE #{date}")
    public int selectShouYiZhuFuCount(String date);

    /**
     * 查询现金利息收入昨日金额
     * @param date
     * @return
     */
    @Select("SELECT money FROM cashAccrualStock ca INNER JOIN  cash c ON c.cashId=ca.cashId WHERE date=#{date}")
    public Integer selectShouYiZfuMoney(String date);

    /**
     * 债券利息收入
     */
    @Select("SELECT date,s.securityName,se.securityType,businessState,money FROM securityAccrualStock se INNER JOIN SECURITY s ON s.securityId=se.securityId WHERE date LIKE #{date} and date=#{date1}  LIMIT #{page},#{limit}")
    public List<ZaiQuanLiXi> selectZhaiQuan(Map map);


    /**
     * 债券利息收入点击统计删除统计过来证券应收应付重复数据
     * @param businessTime
     * @param businessType
     * @param money
     * @return
     */
    @Delete("delete from securityAccrued where businessTime=#{businessTime} and businessType=#{businessType} and money=#{money}")
    public int deletesecurityAccruedd(@Param("businessTime") String businessTime,@Param("businessType") int businessType,@Param("money") int money);


    /**
     * 取证券应收应付库存数据
     * @return
     */
    @Select("SELECT count(*) FROM securityAccrualStock where date=#{date}")
    public int selectZhaiQuanLixiShour(String date);


    /**
     * 查询债券利息收入昨日金额
     * @param date
     * @return
     */
    @Select("SELECT money FROM securityAccrualStock se INNER JOIN SECURITY s ON s.securityId=se.securityId WHERE date=#{date} and se.`securityType`=#{securityType}")
    public Integer selectZhaiQuanMoney(@Param("date") String date,@Param("securityType") int securityType);


    /**
     * 债券利息收入行数
     * @param date
     * @return
     */
    @Select("SELECT count(*) FROM securityAccrualStock se INNER JOIN SECURITY s ON s.securityId=se.securityId WHERE date LIKE #{date}")
    public int selectZhaiQuanCount(String date);



    /**
     * 支付2费
     * @param map
     * @return
     */
    @Select("SELECT businessTime,ca.accountName,businessType,money,fundFlow FROM cashAccrued c INNER JOIN cash ca ON c.cashId=ca.cashId WHERE businessTime LIKE #{businessTime} LIMIT #{page},#{limit}")
    public List<ZfulFeng> selectZhiFu(Map map);


    /**
     * 现金利息收入点击统计删除统计过来资金调拨重复数据
     * @param businessTime
     * @param businessType
     * @param money
     * @return
     */
    @Delete("delete from fundsAllot where businessTime=#{businessTime} and allotType=#{allotType} and allotMoney=#{allotMoney}")
    public int deleteZiJingDiaoB(@Param("businessTime") String businessTime,@Param("allotType") int allotType,@Param("allotMoney") int allotMoney);


    /**
     * 添加现金应收应付
     * @param cashAccrued
     * @return
     */
    @Insert("INSERT INTO cashAccrued VALUES(#{cashAccrued},#{fundId},#{businessTime},#{cashId},#{businessType},#{fundFlow},#{money},#{remark})")
    public int insertXianJinLiXi(CashAccrued cashAccrued);


    /**
     * 取现金应收应付最大的id
     */
    @Select("SELECT MAX(cashAccrued) FROM cashAccrued")
    public String selectDaXianJin();


    /**
     * 取债券应收应付最大的id
     * @return
     */
    @Select("SELECT MAX(securityAccruedId) FROM securityAccrued")
    public String selectDaZhaiQuanId();


    /**
     * 添加资金调拨
     * @param
     * @return
     */
    @Insert("INSERT INTO fundsAllot VALUES(#{fundsAllotId},#{cashId},#{allotType},#{allotDirection},#{allotMoney},#{businessId},#{fundId},#{businessTime},#{allotTime},#{remark})")
    public int insertFundsAllot(FundsAllot fundAllot);


    /**
     * 取资金调拨最大的id
     */
    @Select("SELECT fundsAllotId FROM fundsAllot ORDER BY fundsAllotId  DESC LIMIT 1")
    public String selectZijinDiaoBo();

    /**
     * 证券应收应付添加
     * @param securityAccrued 证券应收应付对象
     * @return
     */
    @Insert("INSERT INTO securityAccrued VALUES(#{securityAccruedId},#{businessTime},#{fundId},#{cashId},#{securityId},#{businessType},#{fundFlow},#{money},#{Remark})")
    public int insertSecurityAccrued(SecurityAccrued securityAccrued);
}
